//
//  NSData+String.m
//  mmbang
//
//  Created by 杨世昌 on 14/12/9.
//  Copyright (c) 2014年 iyaya. All rights reserved.
//

#import "NSData+String.h"

@implementation NSData (String)

/**
 *  data convert gbk string
 *
 *  @return gbk string
 */
- (NSString *)converGBKString
{
    NSStringEncoding gbkEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
    
    NSString *content = [[NSString alloc] initWithData:self
                                              encoding:gbkEncoding];
    
    return content;
}

/**
 *  data convert utf8 string
 *
 *  @return utf8 string
 */
- (NSString *)converUTF8String
{
    NSStringEncoding utf8Encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingUTF8);
    
    NSString *content = [[NSString alloc] initWithData:self
                                              encoding:utf8Encoding];//NSUTF8StringEncoding
    
    return content;
}


-(NSString *)toString
{
    NSString *decodeString = nil;
    @try {
        decodeString=[[NSString alloc] initWithBytes:[self bytes]
                                              length:[self length]
                                            encoding:NSUTF8StringEncoding];
    }
    @catch (NSException *exception) {
        NSLog(@"exception= %@",exception);
    }
    @finally {
        
    }
    
    return decodeString;
}

@end
